/*
 * Copyright 2002-2006 the original author or authors. Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License. You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied. See the License for the specific language governing permissions and limitations under the
 * License.
 */
package pikes.html.xhtml;

import pikes.html.xhtml.CellHAlign.Align;
import pikes.xml.XMLTag;

public aspect CellHAlignAspect {

    private CellHAlignImpl CellHAlign.alignDelegate = new CellHAlignImpl();
    
    public void CellHAlign.setAlign(Align align) {
        alignDelegate.setAlign(align);
    }
    
    public Align CellHAlign.getAlign() {
        return alignDelegate.getAlign();
    }
    
    public void CellHAlign.setChar(Character character) {
        alignDelegate.setChar(character);
    }
    
    public Character CellHAlign.getChar() {
        return alignDelegate.getChar();
    }
    
    pointcut decorateTag(CellHAlign cellHAlign) : execution( protected void TagFactory.decorateCreatedTag(..)) && this(cellHAlign) && !within(CoreAttributesImplementation);
    
    after(CellHAlign cellHAlign) : decorateTag(cellHAlign) {
        XMLTag tag = (XMLTag)thisJoinPoint.getArgs()[0];
        
        cellHAlign.alignDelegate.decorateTag(tag);
        
    }
}

class CellHAlignImpl implements TagDecorator {
    private Align align = null;
    private Character character = null;
    
    public Align getAlign() {
        return align;
    }

    public void setAlign(Align align) {
        this.align = align;
    }
    
    public void setChar(Character character) {
        this.character = character;
    }
    
    public Character getChar() {
        return character;
    }

    public void decorateTag(XMLTag tag) {
        if (align != null) {
            tag.addAttribute("align", align);
        }
        
        if (character != null) {
            tag.addAttribute("char", character.toString());
        }
    }
    
    
}